<?php

namespace app\index\controller;

use app\common\model\Fight as FightModel;
use app\common\model\Persional as PersionalModel;
use think\Exception;

class Index extends Base
{

    //信息
    public function index()
    {
        return view();
    }
    //信息
    public function personal()
    {
        return view();
    }
    //信息
    public function team()
    {
        return view();
    }

    public function persional_edit()
    {
        if (request()->isPost()) {
            $data = input('');
            if (!$data['name']) {
                return returnJson(202, '请输入姓名');
            }
            if (!$data['age']) {
                return returnJson(202, '请输入年龄');
            }
            if (!$data['ball_age']) {
                return returnJson(202, '请输入球龄');
            }
            if (!$data['phone']) {
                return returnJson(202, '请输入联系人联系方式');
            }
            $save_data = [
                'name' => $data['name'],
                'age' => $data['age'],
                'phone' => $data['phone'],
                'ball_age' => $data['ball_age'],
                'sex' => $data['sex'],
                'baoxian' => $data['baoxian'],
                'update_time' => time(),
                'create_time' => time(),
            ];
            $res = PersionalModel::create($save_data);
            if ($res) {
                return returnJson(200, '报名成功', $res);
            } else {
                return returnJson(202, '报名失败');
            }
        }
    }

    public function team_edit()
    {
        if (request()->isPost()) {
            $data = input('');
            if (!$data['name']) {
                return returnJson(202, '请输入球队名称');
            }
            if (!$data['age']) {
                return returnJson(202, '请输入队员年龄');
            }
            if (!$data['ball_age']) {
                return returnJson(202, '请输入球龄');
            }
            if (!$data['member_name']) {
                return returnJson(202, '请输入球队队员');
            }
            if (!$data['color']) {
                return returnJson(202, '请输入队服颜色');
            }
            if (!$data['contact']) {
                return returnJson(202, '请输入联系人');
            }
            if (!$data['phone']) {
                return returnJson(202, '请输入联系方式');
            }
            $save_data = [
                'name' => $data['name'],
                'age' => $data['age'],
                'contact' => $data['contact'],
                'phone' => $data['phone'],
                'ball_age' => $data['ball_age'],
                'member_name' => $data['member_name'],
                'color' => $data['color'],
                'update_time' => time(),
                'create_time' => time(),
            ];
            $res = FightModel::create($save_data);
            if ($res) {
                return returnJson(200, '报名成功', $res);
            } else {
                return returnJson(202, '报名失败');
            }
        }
    }

}
